package com.example.demo.controller;

import java.util.List;

import javax.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.common.CommonEnum;
import com.example.demo.common.JsonResult;
import com.example.demo.dto.EmployeeDetailResponseDto;
import com.example.demo.dto.LoginRequestDto;
import com.example.demo.service.EmployeeService;

/**
 * 社員管理
 */
@RestController
@RequestMapping("/bff/employee")
//If the front end sends a request and a cross domain problem occurs, add this annotation to solve it
@CrossOrigin
public class EmployeeController {

	Logger logger = LoggerFactory.getLogger(EmployeeController.class);

	@Resource
	private EmployeeService employeeService;

	/**
	 * 詳細
	 *
	 * @param requestDto
	 * @return
	 */
	@GetMapping("/detail")
	public JsonResult empDetail(@RequestParam String employeeNumber) {
		if(employeeNumber == null) {
			return JsonResult.error(CommonEnum.PARAM_NOT_MATCH.getResultCode());
		}
		EmployeeDetailResponseDto responseDto = employeeService.empDetail(employeeNumber);
		return JsonResult.success(responseDto);
	}

	/**
	 * query empInfo all
	 * @return
	 */
	@PostMapping("/info")
	public JsonResult empInfo() {
		List<EmployeeDetailResponseDto> empInfoAll = employeeService.empInfo();
		return JsonResult.success(empInfoAll);
	}
}
